// (c)2016 Flipboard Inc, All Rights Reserved.

package com.vxb.testmvp.test_zonghe.test_5;

import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.vxb.testmvp.R;
import com.vxb.testmvp.test_zonghe.entity.ZhuangEntity;
import com.vxb.testmvp.test_zonghe.test_3.ScoreBase;
import com.vxb.testmvp.util.Util;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

public class Test5Adapter extends RecyclerView.Adapter {

    private List<ScoreBase.ScoreData.ScoreContent.Detail> mList;

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item_my_score, parent, false);
        return new Test5ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(final RecyclerView.ViewHolder holder, int position) {
        Test5ViewHolder test5ViewHolder = (Test5ViewHolder) holder;
        final ScoreBase.ScoreData.ScoreContent.Detail detail = mList.get(position);

        test5ViewHolder.tv_content.setText(detail.getContent());
        test5ViewHolder.tv_time.setText(detail.getTimes());
        test5ViewHolder.tv_fixed_score.setText(detail.getScore());
        // 如果设置了回调，则设置点击事件

        test5ViewHolder.tv_fixed_score.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Util.showToast(v.getContext(), "" + detail.getScore());
            }
        });

        if (mOnItemClickLitener != null) {
            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    int pos = holder.getLayoutPosition();
                    mOnItemClickLitener.onItemClick(holder.itemView, pos);
                }
            });
        }


    }

    @Override
    public int getItemCount() {
        return mList == null ? 0 : mList.size();
    }

    public void setItems(List<ScoreBase.ScoreData.ScoreContent.Detail> mList) {
        this.mList = mList;
        notifyDataSetChanged();
    }

    class Test5ViewHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.tv_content)
        TextView tv_content;
        @Bind(R.id.tv_time)
        TextView tv_time;
        @Bind(R.id.tv_fixed_score)
        TextView tv_fixed_score;

        public Test5ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    public interface OnItemClickLitener {
        void onItemClick(View view, int position);
    }

    private OnItemClickLitener mOnItemClickLitener;

    public void setOnItemClickLitener(OnItemClickLitener mOnItemClickLitener) {
        this.mOnItemClickLitener = mOnItemClickLitener;
    }


}
